package com.pzhu.servlet;

import com.pzhu.service.BookService;
import com.pzhu.service.impl.BookServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class DeleteBooksServlet extends HttpServlet {
    BookService bs = new BookServiceImpl();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");

        String s = req.getParameter("id");
        System.out.println(s);
        String[] books = s.split(",|，");
        for (String t: books
             ) {
            System.out.println(t);
            bs.delBook(Integer.parseInt(t));
        }
        resp.sendRedirect("/jdbc/show");
        return;
    }
}
